<div class="submit-form">
    <table class="submit-table">
        <tr id="emailTr">
            <td class="label">电子邮箱：</td>
            <td><input name="email" id="email" class="easyui-textbox" data-options="disabled: true,required:true">
                <a href="javascript:" class="easyui-linkbutton" id="sendEmailVerifyCode" onclick="sendEmailVerifyCode();">发送验证码</a>
            </td>
        </tr>
        <tr id="emailVerifyCodeTr">
            <td class="label">验证码：</td>
            <td><input name="emailVerifyCode" id="emailVerifyCode" class="easyui-textbox" data-options="required:true"></td>
        </tr>
        <tr id="newEmailTr" style="display: none">
            <td class="label">新的电子邮箱：</td>
            <td><input name="newEmail" id="newEmail" class="easyui-textbox" data-options="required:false">
                <a href="javascript:" class="easyui-linkbutton" id="sendNewEmailVerifyCode" onclick="sendNewEmailVerifyCode();">发送验证码</a>
            </td>
        </tr>
        <tr id="newEmailVerifyCodeTr" style="display: none">
            <td class="label">验证码：</td>
            <td><input name="newEmailVerifyCode" id="newEmailVerifyCode" class="easyui-textbox" data-options="required:false"></td>
        </tr>
    </table>
</div>
<style type="text/css">
    .display {
        display: none;
    }
</style>
<script type="text/javascript">
    function sendEmailVerifyCode() {
        $('#email').textbox({disabled: true});
        util.ajax({
            method: 'post',
            url:  Url.User.Api.USER + '/send_email_verify_code_by_current_user',
            success: function (data) {
              if(data) {
                  $.messager.show({title: '信息', msg: '发送成功，请登录电子邮箱查收！'});
              }
                sendEmailVerifyCodeTimedCount();
            },
            error: function (xhr) {
                if(xhr.responseJSON) {
                    $.messager.alert('信息', xhr.responseJSON.message, 'error');
                }
            }
        });
    }
    var c = 60;
    var t;
    function sendEmailVerifyCodeTimedCount() {
        $('#sendEmailVerifyCode').linkbutton({text: c + '秒后可重发', disabled: true});
        if (c <= -1) {
            $('#sendEmailVerifyCode').linkbutton({text: '发送验证码', disabled: false});
            clearTimeout();
            c = 60;
            $('#email').textbox({disabled: false});
        } else {
            c --;
            t = setTimeout("sendEmailVerifyCodeTimedCount()", 1000)
        }
    }

    function sendNewEmailVerifyCode() {
        $('#newEmail').textbox({disabled: true});
        util.ajax({
            method: 'post',
            url:  Url.User.Api.USER + '/send_email_verify_code_by_current_user',
            data: {newEmail: $('#newEmail').textbox('getValue')},
            success: function (data) {
                if(data) {
                    $.messager.show({title: '信息', msg: '发送成功，请登录电子邮箱账号查收'});
                }
                sendNewEmailVerifyCodeTimedCount();
            },
            error: function (xhr) {
                if(xhr.responseJSON) {
                    $.messager.alert('信息', xhr.responseJSON.message, 'error');
                }
            }
        });
    }
    c = 60; t = undefined;
    function sendNewEmailVerifyCodeTimedCount() {
        $('#sendNewEmailVerifyCode').linkbutton({text: c + '秒后可重发', disabled: true});
        if (c <= -1) {
            $('#sendNewEmailVerifyCode').linkbutton({text: '发送验证码', disabled: false});
            clearTimeout();
            c = 60;
            $('#newEmail').textbox({disabled: false});
        } else {
            c --;
            t = setTimeout("sendNewEmailVerifyCodeTimedCount()", 1000)
        }
    }
</script>